package com.deparse.dpframe.ui.activity;

import android.os.Bundle;
import android.os.Message;

/**
 * Created by hsy on 2016/3/8.
 */
public abstract class DPSplashActivity extends DPBaseActivity {

    protected abstract int getSplashContentView();

    protected abstract void doInit();

    protected abstract long getDuration();

    protected abstract void doJump();

    long start = 0, end = start, off = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getSplashContentView());
        start = System.currentTimeMillis();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (start == end) {
            doInit();
        }
        end = System.currentTimeMillis();

        off = getDuration() - (end - start);
        if (off > 0) {
            sendEmptyMessageDelayed(0, off);
        } else {
            doJump();
            finish();
        }
    }

    @Override
    protected void handleMessage(Message msg) {
        super.handleMessage(msg);
        doJump();
        finish();
    }

    @Override
    protected void onStop() {
        super.onStop();
        removeMessage(0);
    }
}
